<template>
  <div>
    <danger-detail-info :form="form"></danger-detail-info>
    <div class="block-box mt-10" v-if="form.Status==50">
      <div class="block-box_item">
          <div class="block-box_title">整改操作</div>
          <van-field class="input_text" name="uploader" label="整改图片" required>
            <template #input>
              <eagle-image-uploader :images.sync="editForm.CorrectiveAttachs"></eagle-image-uploader>
            </template>
          </van-field>
          <van-field
            v-model="editForm.CorrectiveDesc"
            rows="3"
            required
            autosize
            label="整改说明"
            type="textarea"
            placeholder="请输入整改说明"
          />
      </div>
      <div class="btns mt-10 mb-10">
        <van-button class="btn" @click="submit">
          提交
        </van-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getDangerDetail } from "@/api/sytech/sytechDangerCheckTaskDetail";
import { confirmCorrective } from "@/api/sytech/sytechDangerCheckTaskDetail";
import { deepClone } from "@/utils";
import DangerDetailInfo from "@/views/sytech/sytechDangerCheckTaskDetail/DangerDetailInfo.vue";

export default {
  components: { DangerDetailInfo },
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      id: this.$route.query.id,
      form: {},
      editForm: {},
      images:[]
    };
  },
  created() {
    this.geDetail();
  },
  methods: {
    geDetail() {
      getDangerDetail({ id: this.id }).then((res) => {
        this.form = res.data;
        this.editForm = deepClone(res.data);
      });
    },
    onConfirm(date) {
      const dateTime = formatDate(date);
      this.editForm[this.idx] = getDate(dateTime);
      this.showCalendar = false;
    },
    submit() {
      let param = {
        ID: this.editForm.ID,
        CorrectiveDesc: this.editForm.CorrectiveDesc,
        CorrectiveAttachs: this.editForm.CorrectiveAttachs,
      };
      if(!param.CorrectiveAttachs){
        this.$toast("请选择整改图片");
          return false;
      }
      if(!param.CorrectiveDesc){
        this.$toast("请输入整改说明");
          return false;
      }
      confirmCorrective(param)
        .then((res) => {
          this.$toast("提交成功");
          this.$router.goRefresh();
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
  },
};
</script>
